import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;


@WebServlet(name = "servletDemo")
public class servletDemo1 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ServletContext application = this.getServletContext();
        response.setCharacterEncoding("utf-8");
        Integer count = (Integer) application.getAttribute("count");
        if(count!=null) {
            application.setAttribute("count", ++count);
        }else {
            application.setAttribute("count", 1);
        }
        PrintWriter out =response.getWriter();

        out.println("<html>");
        out.println(" <head><title>servlet</title></head>");
        out.println(" <body>");
        out.write("访问次数count="+count);
        out.println(" </body>");
        out.write("</html>");
        out.flush();
        out.close();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
